package demo.config;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.env.Environment;

import demo.bean.SpringInfoBean;
import util.MsgUtil;

@Configuration
public class TestConfig  {
	
	// Springboot注入ApplicationContext的几种方式 http://codefun007.xyz/a/article_detail/1173.htm
 
	////  方法参数的 environment 和 ApplicationContext 会自动注入
	// @Primary
	
	@Bean("springInfoBean")
	public SpringInfoBean springInfoBean(Environment environment){
		
		//
		System.out.println("******TestConfi.springInfoBean.genvironment="+environment);
		System.out.println(environment.getProperty("app.name"));
		
		MsgUtil.add("TestConfig.springInfoBean run");
		
		
	    return new SpringInfoBean("springInfoBean");
	}
	
	@Bean("springInfoBean2")
	@DependsOn("springInfoBean")
	public SpringInfoBean springInfoBean2(ApplicationContext ctx){		
		MsgUtil.add("TestConfig.springInfoBean2 run");
		
		//
		System.out.println("******TestConfi.springInfoBean2.ctx="+ctx);
		Environment environment = ctx.getEnvironment();
		System.out.println("******TestConfi.springInfoBean2.environment="+environment);
		System.out.println(environment.getProperty("app.name"));

	    return new SpringInfoBean("springInfoBean2");
	}

}